package test_unitaire;

import static org.junit.Assert.assertTrue;

import java.util.Calendar;

import org.junit.Test;

import buisness_service.Depense;
import buisness_service.Rapport;
import buisness_service.Revenu;
import buisness_service.User;

public class Test_User {

	@Test
	public void testUser() {
		User u = new User();
		assertTrue(u.getId() == Rapport.nbUser);
		assertTrue(u.getEconomie().getUser() == u);
	}

	@Test
	public void testUserStringStringString() {
		User u = new User();
		assertTrue(u.getId() == Rapport.nbUser);
		assertTrue(u.getEconomie().getUser() == u);
	}

	@Test
	public void testAddDepense() {
		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);
		User u = new User();
		Depense dep = new Depense(20, d, u);

		assertTrue(u.getDepenses().get(0) == dep);
		assertTrue(u.getEconomie().getMontant() == -20);
	
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

	@Test
	public void testAddRevenu() {
		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);
		User u = new User();
		Revenu rev = new Revenu(20, d, u);

		assertTrue(u.getRevenus().get(0) == rev);
		assertTrue(u.getEconomie().getMontant() == 20);
		
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

	@Test
	public void testRemoveDepense() {
		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);
		User u = new User();
		Depense dep = new Depense(20, d, u);
		assertTrue(u.getDepenses().get(0) == dep);
		u.removeDepense(0);
		assertTrue(u.getDepenses().size() == 0);
		
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

	@Test
	public void testRemoveRevenu() {
		Calendar d = Calendar.getInstance();
		d.set(2009, Calendar.DECEMBER, 12);
		User u = new User();
		Revenu dep = new Revenu(20, d, u);
		assertTrue(u.getRevenus().get(0) == dep);
		u.removeRevenu(0);
		assertTrue(u.getRevenus().size() == 0);
		
		Rapport.postesDpenses.clear();
		Rapport.postesRevenus.clear();
	}

}
